package cn.tedu.mybatisexercise1.mapper;

import cn.tedu.mybatisexercise1.pojo.entity.Orders;
import cn.tedu.mybatisexercise1.pojo.vo.OrdersVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.core.annotation.Order;

import java.util.List;

@Mapper
public interface OrdersMapper {
    /**添加一个订单：insert*/
    @Insert("INSERT INTO orders VALUES(NULL,#{state},#{amount},#{created})")
    int insert(Orders orders);

    /**查询所有订单：selectAll*/
    @Select("SELECT * FROM orders")
    List<Orders> selectAll();

    /**通过id查询1个订单：selectOne*/
    @Select("SELECT * FROM orders WHERE id=#{id}")
    Orders selectById(int id);

    /**通过一个id删除订单：deleteById*/
    @Delete("DELETE FROM orders WHERE id=#{id}")
    int deleteById(int id);

    /**统计订单总数：selectCount*/
    @Select("SELECT COUNT(*) FROM orders")
    int selectCount();

    /**查询所有订单的订单状态statas和订单金额amount：封装到 OrderVO*/
    @Select("SELECT state,amount FROM orders")
    List<OrdersVO> selectByCol();
}













